package com.perfect.controller;

import com.perfect.annotation.RequirePermission;
import com.perfect.base.BaseController;
import com.perfect.base.ResultInfo;
import com.perfect.query.ProductPlusQuery;
import com.perfect.query.ProductQuery;
import com.perfect.service.ProductService;
import com.perfect.vo.Product;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

@RequestMapping("product")
@Controller
public class ProductController extends BaseController {

    @Resource
    private ProductService productService;


    //跳转至商品审核展示页面
    @RequirePermission(code = "4010")
    @RequestMapping("productplus/index")
    public String Productplus() {
        return "product/productplus";
    }



    @RequestMapping("productplus/list")
    @RequirePermission(code = "401001")
    @ResponseBody
    //多条件查询商品审核
    public Map<String, Object> queryProductPlusList(ProductPlusQuery productPlusQuery) {
        return productService.selectByParams(productPlusQuery);
    }


    @RequirePermission(code = "402001")
    @RequestMapping("list")
    @ResponseBody
    //多条件查询商品
    public Map<String, Object> queryProductList(ProductQuery productQuery) {

        return productService.selectByParams(productQuery);
    }





    //跳转至商品展示页面
    @RequirePermission(code = "4020")
    @RequestMapping("index")
    public String Product() {
        return "product/product";
    }





    /**
     * 下架商品
     */
    @RequirePermission(code = "402002")
    @PostMapping("delete")
    @ResponseBody
    public ResultInfo deleteProduct(Integer[] ids) {

        // 调用Service层的删除方法
        productService.deleteBatch(ids);
        return success("商品下架成功！");
    }



//跳转至添加商品页面
@RequirePermission(code = "4030")
    @RequestMapping("addproduct")
    public String add_product() {
        return "product/add_product";

    }



//修改审核状态为拒绝状态
@RequirePermission(code = "401002")
    @PostMapping("deleteplus")
    @ResponseBody
    public ResultInfo deleteProductPlus(Integer[] ids) {

        // 调用Service层的删除方法
        productService.deleteProductPlusBatch(ids);
        return success("拒绝成功！");
    }




//修改审核为成功状态
@RequirePermission(code = "401003")
    @PostMapping("updateproductplus")
    @ResponseBody
    public ResultInfo updateproductplus(Integer proId) {
        System.out.println(proId+"---------------------");

        // 调用Service层的删除方法
        productService.updateProductPlus(proId);
        return success("成功通过！");
    }




    //添加商品
    @RequirePermission(code = "403001")
    @PostMapping("merchant/add")
    @ResponseBody
    public ResultInfo addProduct(Product product,String desc, HttpServletRequest request) {

        // 调用Service层的添加方法
        productService.addProduct(product,desc);

        return success("商品添加成功！");
    }

    /**
     * 查询不同种类的商品总数
     * @return
     */
    @RequestMapping("productCount")
    @ResponseBody
    public Map<String,Object> productCount(){
        return productService.listProductCount();
    }
}
